package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.utils.PageUtils;
import com.atguigu.srb.common.utils.R;
import com.atguigu.srb.core.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author cfx
 * @since 2022-06-25
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
//@CrossOrigin
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户列表")
    @GetMapping("/list")
    public R listPage(@RequestParam Map<String, Object> params) {
        PageUtils page = userInfoService.queryPage(params);
        return R.ok().put("page", page);
    }

    @ApiOperation("锁定和解锁")
    @PutMapping("/lock/{id}/{status}")
    public R lockAndUnlock(
            @ApiParam(value = "用户id", required = true)
            @PathVariable("id") Long id,

            @ApiParam(value = "锁定状态（0：锁定 1：解锁）", required = true)
            @PathVariable("status") Integer status) {

        userInfoService.lock(id, status);
        return R.ok(status==1?"解锁成功":"锁定成功");
    }


}

